﻿using System.Collections.Generic;
using RanchBuddy.Core.DataAccess;
using RanchBuddy.Core.Domain.Impl;
using StructureMap;

namespace RanchBuddy.Core.Services.Impl
{
    [Pluggable("Default")]
    public class CompanyService : ICompanyService
    {
        public List<Company> GetCompanies(int zipcode,int radius, int page, int count)
        {
            List<Company> result = new List<Company>();
            IRepositoryStatus rs = ObjectFactory.GetInstance<ICompanyRepository>().GetCompanies(page, count, zipcode, radius);
            if (rs.StatusType == Status.StatusTypes.Success)
                result = rs.GetObject<List<Company>>();
            return result;
            
        }

        public Company GetCompanyByName(string CompanyName)
        {
            Company result = new Company();
            IRepositoryStatus rs = ObjectFactory.GetInstance<ICompanyRepository>().GetCompanyByName(CompanyName);
            if (rs.StatusType == Status.StatusTypes.Success)
                result = rs.GetObject<Company>();
            else
                result = null;
            return result;
        }

        public Company GetCompanyByID(int companyID)
        {
            Company result = new Company();

            IRepositoryStatus rs = ObjectFactory.GetInstance<ICompanyRepository>().GetCompanyByID(companyID);
            if (rs.StatusType == Status.StatusTypes.Success)
                result = rs.GetObject<Company>();
            else
                result = null;

            return result;
        }
    }
}
